#include<iostream>
#include<unistd.h>
using namespace std;
#include"Thread.hpp"
#include"lockguard.hpp"

using namespace std;

pthread_mutex_t at = PTHREAD_MUTEX_INITIALIZER;
int cnt = 1000;
void Print(int n)
{
    while(1)
    {
        LockGuard lg(&at);
        if(cnt > 0)
        {
            sleep(1);
            printf("%d : %d\n",n,cnt);
            cnt--;
        }
        else{
            break;
        }
    }
}

int main()
{
    pthread_mutex_t t;
    pthread_mutex_init(&t,nullptr);
    Thread<int> t5("Tread-1",Print,5);
    Thread<int> t4("Tread-1",Print,4);
    Thread<int> t3("Tread-1",Print,3);
    Thread<int> t2("Tread-1",Print,2);
    Thread<int> t1("Tread-1",Print,1);
    t5.Start();
    t4.Start();
    t3.Start();
    t2.Start();
    t1.Start();

    t5.Join();
    t4.Join();
    t3.Join();
    t2.Join();
    t1.Join();
    
    return 0;
}


